import com.noppanit.library.model.*
import com.noppanit.library.interfaces.*
import com.noppanit.library.implement.*
import org.apache.lucene.*
import org.apache.lucene.store.*

class LibraryController {

    def search = 
    {
		def query = params.query
		def description = params.description
		if(!query.is("") && query != null)
		{
			Directory directory
			LibrarianInterface library
			Book[] books
			try
			{
				directory = FSDirectory.getDirectory('lucene-index' );
				library = new Librarian();
				books = library.search(directory,query,description)
				
			}
			catch(Exception e)
			{
				render("Index files not found")
			}
			return [books: books]
		}
		else 
			return null
	
    }

}
